package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.NursingProjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/serve/project")
@RequiredArgsConstructor
public class NursingProjectController {

    private final NursingProjectService nursingProjectService;

    @GetMapping("/list")
    public Result PageNursinngProjects(PageNursingQueryParam pageNursingQueryParam) {
        PageResult<NursingProject> pageResult = nursingProjectService.PageNursinngProjects(pageNursingQueryParam);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result save(@RequestBody NursingProject nursingProject) {
        boolean save = nursingProjectService.save(nursingProject);
        if (save) {
            return Result.success();
        }
        return Result.error();
    }

    @PutMapping
    public Result update(@RequestBody NursingProject nursingProject) {
        boolean update = nursingProjectService.updateById(nursingProject);
        if (update) {
            return Result.success();
        }
        return Result.error();
    }

    //根据id查询护理
    @GetMapping("/{id}")
    public Result getById(@PathVariable long id) {
        NursingProject nursingProject = nursingProjectService.getById(id);
        return Result.success(nursingProject);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable long id) {
        boolean delete = nursingProjectService.removeById(id);
        if (delete) {
            return Result.success();
        }
        return Result.error();
    }

    @GetMapping("/all")
    public Result list() {
        List<NursingProjectResule> list = nursingProjectService.selectList();
        return Result.success(list);
    }
}


